package hsl.haxe;
import hsl.haxe.argument.ListenerArgument;
import hsl.haxe.bond.Bond;

class Signaler<Datatype> {
	private var bonds:List<Bond<Datatype>>;
	private var subject:Subject;
	public function new(subject:Subject):Void {
		this.subject = subject;
		bonds = new List();
	}
	public function bindNiladic(listener:Void -> Dynamic):Void {
		bonds.add(new hsl.haxe.bond.NiladicBond(listener));
	}
	public function bindMonadic<ArgumentType>(listener:ArgumentType -> Dynamic, argument:ListenerArgument<ArgumentType, Datatype>):Void {
		bonds.add(new hsl.haxe.bond.MonadicBond(listener, argument));
	}
	public function bindDyadic<FirstArgumentType, SecondArgumentType>(listener:FirstArgumentType -> SecondArgumentType -> Dynamic, firstArgument:ListenerArgument<FirstArgumentType, Datatype>, secondArgument:ListenerArgument<SecondArgumentType, Datatype>):Void {
		bonds.add(new hsl.haxe.bond.DyalicBond(listener, firstArgument, secondArgument));
	}
	public function bindTriadic<FirstArgumentType, SecondArgumentType, ThirdArgumentType>(listener:FirstArgumentType -> SecondArgumentType -> ThirdArgumentType -> Dynamic, firstArgument:ListenerArgument<FirstArgumentType, Datatype>, secondArgument:ListenerArgument<SecondArgumentType, Datatype>, thirdArgument:ListenerArgument<ThirdArgumentType, Datatype>):Void {
		bonds.add(new hsl.haxe.bond.TriadicBond(listener, firstArgument, secondArgument, thirdArgument));
	}
	//public function bindTetradic;
	//public function bindPentadic;
	//public function bindHexadic;
	//public function bindHeptadic;
	//public function bindOctadic;
	public function dispatch(value:Datatype):Void {
		for (bond in bonds) {
			bond.callListener(value, subject);
		}
	}
}
